<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8" />
		<title>鼠标交互</title>
		<style type="text/css">
			* {
				padding: 0;
				margin: 0;
			}
			
			.container {
				width: 100vw;
				height: 100vh;
				display: flex;
				align-items: center;
				justify-content: center;
			}
			
			canvas {
				width: 500px;
				height: 500px;
				border: 2px solid blue;
			}
		</style>
	</head>

	<body>
		<div class="container">
			<canvas id="canvas" width="500" height="500"></canvas>
		</div>
	</body>
	<script type="text/javascript">
		window.onload = function() {
			let oCanvas = document.getElementById('canvas');
			console.dir(oCanvas);
			let oPen = oCanvas.getContext("2d");

			document.onmousemove = function(e) {
				//console.dir('x='+(e.pageX-oCanvas.offsetLeft))
				//console.dir('y='+(e.pageY-oCanvas.offsetTop))
			}
			document.onmousedown = function(e) {
				//console.dir('x='+(e.pageX-oCanvas.offsetLeft))
				//console.dir('y='+(e.pageY-oCanvas.offsetTop))
			}
			document.onmouseup = function(e) {
				console.dir('x=' + (e.pageX - oCanvas.offsetLeft))
				console.dir('y=' + (e.pageY - oCanvas.offsetTop))
			}
		}
	</script>
	</body>

</html>